package com.njust.controller;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class FaviconController {

    @GetMapping("/favicon.ico")
    public ResponseEntity<InputStreamResource> getFavicon() throws IOException {
        ClassPathResource imgFile = new ClassPathResource("static/favicon.ico"); // 路径根据实际情况调整

        return ResponseEntity
                .ok()
                .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + imgFile.getFilename() + "\"")
                .contentType(MediaType.parseMediaType("image/x-icon"))
                .body(new InputStreamResource(imgFile.getInputStream()));
    }
}
